﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using FrontDisplay.NativeMethods;

namespace FrontDisplay.Power
{

    /// <summary>
    /// Interaction logic for PowerPage.xaml
    /// </summary>
    public partial class PowerPage : UserControl
    {
        public PowerPage()
        {
            InitializeComponent();

            RestartImage.Source = Utility.LoadBitmap(Properties.Resources.Reboot);
            SleepImage.Source = Utility.LoadBitmap(Properties.Resources.Standby);
            ShutdownImage.Source = Utility.LoadBitmap(Properties.Resources.Shutdown);

            IsVisibleChanged += PowerPageIsVisibleChanged;
        }

        private void PowerPageIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                //Focus();
                //SleepButton.Focus();
            }
        }

        private void BackButtonMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.NavigateBack();
        }

        private void RestartButtonClick(object sender, RoutedEventArgs e)
        {
            Navigation.Navigate(InfoPage.Instance);

            WinApi.DoExitWin(WinApi.ExitWindows.Reboot);
        }

        private void SleepButtonClick(object sender, RoutedEventArgs e)
        {
            Navigation.Navigate(InfoPage.Instance);

            System.Windows.Forms.Application.SetSuspendState(System.Windows.Forms.PowerState.Suspend, true, true);
        }

        private void ShutdownButtonClick(object sender, RoutedEventArgs e)
        {
            Navigation.Navigate(InfoPage.Instance);

            WinApi.DoExitWin(WinApi.ExitWindows.ShutDown);
        }
    }
}
